public class FileTypeDetector {
    private static final Map<String, String> MIME_TYPES = new HashMap<>();
    
    static {
        // 文档类型
        MIME_TYPES.put("pdf", "application/pdf");
        MIME_TYPES.put("docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
        MIME_TYPES.put("xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        
        // 图片类型
        MIME_TYPES.put("jpg", "image/jpeg");
        MIME_TYPES.put("png", "image/png");
        
        // 音频类型
        MIME_TYPES.put("mp3", "audio/mpeg");
        MIME_TYPES.put("wav", "audio/wav");
    }
    
    public String detectFileType(File file) {
        try {
            String contentType = Files.probeContentType(file.toPath());
            return MIME_TYPES.entrySet()
                    .stream()
                    .filter(entry -> entry.getValue().equals(contentType))
                    .map(Map.Entry::getKey)
                    .findFirst()
                    .orElse("unknown");
        } catch (IOException e) {
            return "unknown";
        }
    }
} 